#ifndef __time_controller_h_
#define __time_controller_h_
#include "adevs/adevs.h"
#include "io_type.h"
#include "controller.h"

class TimeController: public Controller
{
	public:
		/// Constructor.
		TimeController();
		/// Internal transition function.
		void delta_int();
		/// External transition function.
		void delta_ext(double e, const adevs::Bag<IO_Type>& xb);
		/// Confluent transition function.
		void delta_conf(const adevs::Bag<IO_Type>& xb);
		/// Output function.  
		void output_func(adevs::Bag<IO_Type>& yb);
		/// Time advance function.
		double ta();
		/// Output value garbage collection.
		void gc_output(adevs::Bag<IO_Type>& g);
		/// Destructor.
		~TimeController();

		void set_phase_length(int side, double pl) {phase_length[side] = pl;};

	private:
		/// Default settings
		static const double DEFAULT_PHASE_LENGTH;

		/// Status variables
		double remaining_time;
		int current_side_green;

		/// Setting variables
		double phase_length[4];

		/// Auxiliary methods
		int next_side_green() { return (current_side_green+1) % get_sides_count(); }
};

#endif
